#include<iostream>
#include<thread>
#include<vector>
#include<unistd.h>
#include<mutex>

using namespace std;

int x = 0;


int main()
{
	int n = 10000;
	mutex mtx;

  std::thread t1([&]()
		{
			mtx.lock();
			for (int i = 0; i < n; ++i)
			{
				++x;
			}
			mtx.unlock();
		});

  std::thread t2([&]()
		{
			mtx.lock();
			for (int i = 0; i < n; ++i)
			{
				++x;
			}
			mtx.unlock();
		});

	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;
	cout << x << endl;

	t1.join();
	t2.join();

	cout << x << endl;

	return 0;
}
